import { BasicFetchResult } from '../model/baseModel';
import { defHttp } from '@/utils/http/axios';
import { downloadBlob } from '@/utils/file/download';
import { ContentTypeEnum } from '@/enums/httpEnum';
const api = '/sysSubjectConfig'
/**
 * 查询会计科目表不分页
 * @author frank
 * @date 2023-10-20 09:17:22
 */
export const list = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: api + '/list', params });
/**
 * 添加会计科目表
 * @author frank
 * @date 2023-10-20 09:17:22
 */
export const add = (params?: any) => defHttp.post({ url: api + '/add', params });
/**
 * 修改会计科目表
 * @author frank
 * @date 2023-10-20 09:17:22
 */
export const edit = (params?: any) => defHttp.post({ url: api + '/edit', params });

/**
 * 删除会计科目表
 * @author frank
 * @date 2023-10-20 09:17:22
 */
export const del = (ids: string[]) =>
  defHttp.post({ url: api + '/delete', params: ids });
/**
 * 导出会计科目表
 * @author frank
 * @date 2023-10-20 09:17:22
 */
export const exp = (params?: any) => {
  return new Promise<void>((resolve, reject) => {
    defHttp
      .get(
        { responseType: 'blob', url: api + '/export', params },
        { isReturnNativeResponse: true },
      )
      .then((res) => {
        downloadBlob(res);
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};

export const imp = (params: any) =>
  defHttp.post({
    headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
    url: api + '/import',
    params,
  });
